#include <bits/stdc++.h>
using namespace std;

//#define LOCAL

#ifdef LOCAL
template<typename T>
void err(T v) {
    cerr << v << endl;
}

void err() {
    cerr << endl;
}
template<typename T, typename... A>
void err(T v, A... args) {
    cerr << v << ", ";
    err(args...);
}
#define dbg(x...) { cerr << #x << " -> "; err(x);}

#else
#define dbg(...)

#endif

typedef long long LL;

const int N = 2e5+50;
int n;
int a[N], b[N];
LL s[N];
map<LL, int> mp;
int check() {
    int ans = 0;
    for (int i=1; i<=n; ++i) {
        for (int j=i; j<=n; ++j) {

            bool suc = true;
            for (int k=i; k<=j; ++k) {
                for (int l=k; l<=j; ++l) {
                    if (s[l] - s[k-1] == 0)
                        suc = false;
                }
            }
//            if (!suc)
//                dbg(i, j);
            ans += suc;
        }
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for (int i=1; i<=n; ++i) {
        scanf("%d", &a[i]);
    }
//    n = 100;
//    for (int i=1; i<=n; ++i) {
//        a[i] = rand()%40-20;
//        dbg(i, a[i]);
//    }
    LL sum = 0;
    mp[0] = 0;
    int cur = -1;
    LL ans = 1LL*n*(n+1)/2;
    for (int i=1; i<=n; ++i) {
        sum += a[i];
        s[i] = sum;
        if (a[i] == 0)
            mp[0] = i-1;
        if (mp.count(sum) && mp[sum] > cur) {
//            dbg(i, cur, sum, mp[sum], -(cur - mp[sum]) * (n-i+1));
            ans += 1LL * (cur - mp[sum]) * (n-i+1);
            cur = mp[sum];
        }

        mp[sum] = i;
    }
    printf("%lld\n", ans);
//    dbg(check());
    return 0;
}